/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.mrp.ppm.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;

/**
 *
 * @author Zhu Xin
 */
@Entity
public class WeeklyMPS implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private Integer startPeriodYear;
    private Integer startPeriodMonth;
    
    @OrderBy("productIndex")
    @OneToMany(targetEntity=IndivWMPS.class, cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    private Collection<IndivWMPS> indivWMPSList = new ArrayList<IndivWMPS>();
    
    @OneToMany(targetEntity=MRP.class,cascade={CascadeType.MERGE},fetch=FetchType.EAGER)
    private List<MRP> mrps;

    public WeeklyMPS() {
    }

    public WeeklyMPS(Integer startPeriodYear, Integer startPeriodMonth) {
        this.startPeriodYear = startPeriodYear;
        this.startPeriodMonth = startPeriodMonth;
        for (int i = 0; i < 4; i++){
            // represent the 4 products
            IndivWMPS temp = new IndivWMPS();
            temp.setProductIndex(i);
            indivWMPSList.add(temp);
        }
    }
    
    public IndivWMPS returnProductIndivSOP(int i){
        List<IndivWMPS> temp = (List<IndivWMPS>) indivWMPSList;
        return temp.get(i);
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Collection<IndivWMPS> getIndivWMPSList() {
        return indivWMPSList;
    }

    public void setIndivWMPSList(Collection<IndivWMPS> indivWMPSList) {
        this.indivWMPSList = indivWMPSList;
    }

    public Integer getStartPeriodMonth() {
        return startPeriodMonth;
    }

    public void setStartPeriodMonth(Integer startPeriodMonth) {
        this.startPeriodMonth = startPeriodMonth;
    }

    public Integer getStartPeriodYear() {
        return startPeriodYear;
    }

    public void setStartPeriodYear(Integer startPeriodYear) {
        this.startPeriodYear = startPeriodYear;
    }

    public List<MRP> getMrps() {
        return mrps;
    }

    public void setMrps(List<MRP> mrps) {
        this.mrps = mrps;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {

        if (!(object instanceof WeeklyMPS)) {
            return false;
        }
        WeeklyMPS other = (WeeklyMPS) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.mrp.ppm.entity.WeeklyMPS[ id=" + id + " ]";
    }
    
}
